package com.beyond.trace.job;


import com.beyond.trace.service.FruitManageService;
import com.beyond.trace.service.warn.WarnRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @ClassName: TaskWarnRecord
 * @author: z越
 * @date: 2023/2/27  10:13
 * @description 同步设备数据 根据规则生成预警信息
 */
@Slf4j
@Component
@RequiredArgsConstructor
@EnableScheduling
public class Task {

    private final WarnRecordService warnRecordService;
    private final FruitManageService fruitManageService;

    //定时根据预警规则 发送预警短信
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void taskWarnRuleFinish() {
        log.info("开始据预警规则发送预警短信定时任务");
        try {
            warnRecordService.insertWarnRecord();
        } catch (Exception e) {
            log.error("定时预警规则发送预警短信定时任务失败", e);
        }
        log.info("结束据预警规则发送预警短信定时任务");
    }

    //定时爬取水果行情网站桃子数据
    @Scheduled(cron = "0 0 1 * * ? ")
    public void taskJsoupFinish() {
        log.info("开始定时爬取水果行情网站桃子数据定时任务");
        try {
            fruitManageService.insertData();
        } catch (Exception e) {
            log.error("定时爬取水果行情网站桃子数据定时任务失败", e);
        }
        log.info("结束定时爬取水果行情网站桃子数据定时任务");
    }

}
